package com.yikaiye.android.yikaiye.pay;

import android.content.Context;
import android.widget.Toast;

import com.tencent.mm.opensdk.modelpay.PayReq;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.yikaiye.android.yikaiye.config.Constant;

/**
 * 微信支付
 */
public class WeChatPay {
    public void pay(Context context, WeChatInfoModel weChatInfoModel){
        IWXAPI api = WXAPIFactory.createWXAPI(context, null);
        api.registerApp(Constant.WE_CHAT_APP_ID);
        PayReq req = new PayReq();
        req.appId 			= Constant.WE_CHAT_APP_ID;
        req.partnerId 		= weChatInfoModel.getPartnerid();
        req.prepayId		= weChatInfoModel.getPrepayid();
        req.packageValue 	= "Sign=WXPay";
        req.nonceStr		= weChatInfoModel.getNoncestr();
        req.timeStamp		= weChatInfoModel.getTimestamp();
        req.sign			= weChatInfoModel.getSign();
//        req.sign			= "MD5";
//        Toast.makeText(context, "正常调起支付", Toast.LENGTH_SHORT).show();
        // 在支付之前，如果应用没有注册到微信，应该先调用IWXMsg.registerApp将应用注册到微信
        api.sendReq(req);
    }
}
